import request from "@/utils/request";
import {AxiosPromise} from "axios";
import {CrawlTemplateForm, CrawlTemplateMockForm, CrawlTemplatePageResult, CrawlTemplateQuery,} from "./types";

/**
 * 爬虫模板分页列表
 *
 * @param data
 */
export function getPage(
	data: CrawlTemplateQuery
): AxiosPromise<CrawlTemplatePageResult> {
	return request({
		url: "/api/v1/crawl/template/page",
		method: "post",
		data: data,
	});
}

/**
 * 爬虫模板表单数据
 *
 * @param id
 */
export function getForm(id: number): AxiosPromise<CrawlTemplateForm> {
	return request({
		url: "/api/v1/crawl/template/" + id + "/form",
		method: "get",
	});
}

/**
 * 新增爬虫模板
 *
 * @param data
 */
export function add(data: CrawlTemplateForm) {
	return request({
		url: "/api/v1/crawl/template/add",
		method: "post",
		data: data,
	});
}

/**
 * 修改爬虫模板
 *
 * @param id
 * @param data
 */
export function update(id: number, data: CrawlTemplateForm) {
	return request({
		url: "/api/v1/crawl/template/" + id,
		method: "put",
		data: data,
	});
}

/**
 * 删除爬虫模板
 */
export function del(ids: string) {
	return request({
		url: "/api/v1/crawl/template/" + ids,
		method: "delete",
	});
}

/**
 * 开启|关闭爬虫模板
 */
export function switchStatus(id: number) {
	return request({
		url: "/api/v1/crawl/template/" + id + "/switchStatus",
		method: "put",
	});
}

/**
 * 执行爬虫任务
 */
export function run(id: number) {
	return request({
		url: "/api/v1/crawl/template/" + id + "/run",
		method: "put",
	});
}


/**
 * MOCK运行模板
 *
 */
export function mockRun(data: CrawlTemplateMockForm) {
	return request({
		url: "/api/v1/crawl/template/mockRun",
		method: "post",
		data: data
	});
}
